<template>
  <div class="trade_header">
    <div class="h_left">
      <div class="hl_m">
        <div class="hl_1">用户名</div>
        <div class="hl_2">
          <Select v-model="clientSelected" style="width:140px">
            <Option v-for="(item,client_key) in client_list" :value="item" :key="client_key">{{ item }}</Option>
          </Select>
<!--          <button  @click="get_clientSelected">交易区</button>-->
          <button  @click="trade_main_modal = true;get_BasicParameter2();get_BatchParameter2()">交易区</button>
        </div>
        <div class="hl_3">
          <div class="price" v-if="price.price_of_stop_profit_and_stop_loss ==='price_index'">
            <label>指数价</label>
            <em>{{price.price_index}}</em>
          </div>
          <div class="price" v-else>
            <!--<label>市价</label>-->
            <!--<em>{{price.price_now}}</em>-->

            <Select v-model="contractSelected"@on-change="contract_selected" style="width: 140px">
              <Option v-for="(item,contract_key) in contract_list" :value="item" :key="contract_key">{{ item }}</Option>
            </Select>

          </div>
          <div class="hl_wt">
            <button @click="synchronous_modall = true">同步委托</button>
          </div>
        </div>
      </div>
    </div>
    <div class="d1"></div>
    <div class="h_main">
      <div class="hm_m">
        <div class="hm_1">基本信息</div>
        <div class="hm_2">
          <div class="hm_2_list">
            <p>当前权益</p>
            <p class="hm_2_p2">{{client_info.basic.static}}</p>
            <p class="hm_2_p2">${{client_info.basic.cny}}</p>
          </div>
          <!--          <div class="hm_2_list">-->
          <!--            <p>美元</p>-->
          <!--            <p class="hm_2_p2">${{client_info.basic.cny}}</p>-->
          <!--          </div>-->
          <div class="hm_2_list">
            <p>多方持仓</p>
            <p class="hm_2_p2 mygreen" >{{client_info.basic.buy_volume}}</p>

          </div>
          <div class="hm_2_list">
            <p>空方持仓</p>
            <p class="hm_2_p2 myred" >{{client_info.basic.sell_volume}}</p>
          </div>
          <!--          <div class="hm_2_list">-->
          <!--            <p>已盈亏</p>-->
          <!--            <p class="hm_2_p2">{{client_info.basic.profit_real}}</p>-->
          <!--          </div>-->
          <!--          <div class="hm_2_list">-->
          <!--            <p>未盈亏</p>-->
          <!--            <p class="hm_2_p2">{{client_info.basic.profit_unreal}}</p>-->
          <!--          </div>-->
          <div class="hm_2_list">
            <p>最低净值</p>
            <p class="hm_2_p2" style="color:orange">{{client_info.basic.lowest_net_worth}}</p>
          </div>
        </div>
      </div>
    </div>
    <div class="d2"></div>
    <div class="h_centre">
      <div class="hm_m">
        <div class="hm_1">
          <span class="hm_1_s">盈亏</span>
          <i-switch v-model="client_info.profit_loss_cal_status_unrun" @on-change="max_profit_and_loss_change" :disabled=flag size="small"/>
        </div>
        <div class="hm_2">
          <div class="col-th">
            <div class="col-td">
              <p>$</p>
            </div>
            <div class="col-td">
              <p>直涨</p>
            </div>
            <div class="col-td">
              <p>循涨</p>
            </div>
            <div class="col-td">
              <p>直跌</p>
            </div>
            <div class="col-td">
              <p>循跌</p>
            </div>
          </div>
          <div class="col-tr" v-for="(profit_and_loss, profit_and_loss_index) in client_info.max_profit_and_loss_data" :key="profit_and_loss_index">
            <div class="col-td">
              <p style="color:orange;">{{profit_and_loss.name}}</p>
            </div>
            <div class="col-td">
              <p>{{profit_and_loss.c1}}</p>
            </div>
            <div class="col-td">
              <p>{{profit_and_loss.c2}}</p>
            </div>
            <div class="col-td">
              <p>{{profit_and_loss.c3}}</p>
            </div>
            <div class="col-td">
              <p>{{profit_and_loss.c4}}</p>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="d3"></div>
    <div class="h_right">
      <div class="hr_m">
        <div class="hr_1">风险控制</div>
        <div class="hr_2">
          <div class="hr_2_list">
            <p>下终止</p>
            <p class="hr_2_p2" v-if="client_info.risk.end_down !== 'None'">{{client_info.risk.end_down}}</p>
            <p class="hr_2_p2" v-else></p>
            <i @click = 'update_risk("下终止")'></i>
          </div>
          <div class="hr_2_list">
            <p>上终止</p>
            <p class="hr_2_p2" v-if="client_info.risk.end_up !== 'None'">{{client_info.risk.end_up}}</p>
            <p class="hr_2_p2" v-else></p>
            <i @click = 'update_risk("上终止")'></i>
          </div>
          <div class="hr_2_list" style="width: 125px">
            <p>止损时间</p>
            <p class="hr_2_p2" v-if="client_info.risk.end_time !== 'None' && end_time !== 'None'">{{end_time}}</p>
            <p class="hr_2_p2" v-else></p>
            <i @click = 'update_risk("止损时间")'></i>
          </div>
          <div class="hr_2_list">
            <p>最大多仓</p>
            <p class="hr_2_p2 mygreen" >{{client_info.risk.buy_volume_max}}</p>
          </div>
          <div class="hr_2_list">
            <p>最大空仓</p>
            <p class="hr_2_p2 myred" >{{client_info.risk.sell_volume_max}}</p>
          </div>
          <div class="hr_2_list">
            <p>当前强平</p>
            <p class="hr_2_p2" v-if="client_info.risk.liquidation_price !== 'None'">{{client_info.risk.liquidation_price}}</p>
            <p class="hr_2_p2 " v-else>--</p>
          </div>
          <div class="hr_2_list">
            <p>多单强平</p>
            <p class="hr_2_p2 mygreen" >{{client_info.risk.liquidation_buy}}</p>
          </div>
          <div class="hr_2_list">
            <p>空单强平</p>
            <p class="hr_2_p2 myred"  v-if="client_info.risk.liquidation_sell !== '99999999'">{{client_info.risk.liquidation_sell}}</p>
            <p class="hr_2_p2 myred" v-else style="font-size: 26px;margin-top: 5px; font-family: not;">+∞</p>
            <!--<p class="hr_2_p2 myred" v-else style="font-size: 18px; margin-top: 5px">+<span style="display: inline-block; font-size: 26px;" class="iconfont iconwuqiongda" ></span></p>-->
          </div>
        </div>
      </div>
    </div>
    <div class="h_extra">
      <button @click="clickSprint()" class="he_button1">冲刺</button>
      <button @click="auto_start_modall=true;getListAutorun()" class="he_button2">自动启动</button>
      <button @click="point_location_modall=true ;getPointLocation()" class="he_button3">自动平移</button>
      <button @click="time_triggered_modall=true ;getListTimePrice()" class="he_button4">自动离场</button>
    </div>
    <div class="modal">
      <Modal
        v-model="risk_modall"
        :title="risk_modall_title"
        :mask-closable = "false"
        @on-ok ="risk_save"
        @on-cancel ="risk_cancel"
        :loading ='true'
        width="440">
        <div>
          <Form>
            <FormItem label="下终止" :label-width="130" style="margin-bottom: 10px;" v-if="this.risk_modall_title == '修改下终止'">
              <Input v-model="updata_risk.end_down" style="width: 210px"></Input>
              <Button @click="updata_risk.end_down = 'None'">置空</Button>
            </FormItem>
            <FormItem label="下终止平仓方式" :label-width="130" style="margin-bottom: 10px;" v-if="this.risk_modall_title == '修改下终止'">
              <Select v-model="updata_risk.end_down_type" style="width: 210px">
                <Option value="被动">被动</Option>
                <Option value="主动">主动</Option>
              </Select>
            </FormItem>
            <FormItem label="下终止价格类型" :label-width="130" style="margin-bottom: 10px;" v-if="this.risk_modall_title == '修改下终止'">
              <Select v-model="updata_risk.end_down_price_type" style="width: 210px">
                <Option value="市价">市价</Option>
                <Option value="指数价">指数价</Option>
                <Option value="EMA">EMA</Option>
              </Select>
            </FormItem>
            <FormItem label="上终止" :label-width="130" style="margin-bottom: 10px;" v-if="this.risk_modall_title == '修改上终止'">
              <Input v-model="updata_risk.end_up" style="width: 210px"></Input>
              <Button @click="updata_risk.end_up = 'None'">置空</Button>
            </FormItem>
            <FormItem label="上终止平仓方式" :label-width="130" style="margin-bottom: 10px;" v-if="this.risk_modall_title == '修改上终止'">
              <Select v-model="updata_risk.end_up_type" style="width: 210px">
                <Option value="被动">被动</Option>
                <Option value="主动">主动</Option>
              </Select>
            </FormItem>
            <FormItem label="上终止价格类型" :label-width="130" style="margin-bottom: 10px;" v-if="this.risk_modall_title == '修改上终止'">
              <Select v-model="updata_risk.end_up_price_type" style="width: 210px">
                <Option value="市价">市价</Option>
                <Option value="指数价">指数价</Option>
                <Option value="EMA">EMA</Option>
              </Select>
            </FormItem>
            <FormItem label="止损时间" :label-width="130" style="margin-bottom: 10px;" v-if="this.risk_modall_title == '修改止损时间'">
              <DatePicker  type="datetime"  v-model="updata_risk.end_time"></DatePicker >
            </FormItem>
            <FormItem label="止损时间平仓方式" :label-width="130" style="margin-bottom: 10px;" v-if="this.risk_modall_title == '修改止损时间'">
              <Select v-model="updata_risk.end_time_type" style="width: 200px">
                <Option value="被动">被动</Option>
                <Option value="主动">主动</Option>
              </Select>
            </FormItem>
          </Form>
        </div><!--注册界面组件-->
      </Modal>
      <Modal
        v-model="synchronous_modall"
        ok-text="确定"
        cancel-text="取消"
        :mask-closable = "false"
        :loading ='true'
        @on-ok="synchronous()"
      >
        <p>确认要同步委托吗？</p>
      </Modal>
      <Modal
        v-model="trade_main_modal"
        :closable = false
        :mask-closable = false
        :footer-hide = true
        width="1570"
        class="trade_main_modal"
        :styles="{top: '220px'}"
      >
        <trade_main @on-close-modal="close_modal"></trade_main>
      </Modal>


      <Modal
        v-model="sprint_modall"
        :title="sprint_modall_title"
        class="mycolor_modal"
        :footer-hide="true"
        :mask-closable = "false"
        width="1750">
        <div class="modal_header" style="display: flex;">
          <div class="modal_form" style="margin-left: 10px">
            <div style="margin-left: 15px">
              <label style="font-weight: 800;letter-spacing:2px;font-size: 16px">执行方式</label>
            </div>
            <div style="margin-top: 7px">
              <Select v-model="sprint.sprint_trigger_type"  style="width:100px" >
                <Option value="立即执行" >立即执行</Option>
                <Option value="价格时间" >价格时间</Option>
              </Select>
            </div>
          </div>
          <div class="modal_form" style="margin-left: 30px">
            <div>
              <DatePicker  type="datetime"  placeholder="时间" v-model="sprint.time" :disabled="sprint.sprint_trigger_type =='立即执行'"></DatePicker >
              <Select v-model="sprint.before_after_time" style="width: 80px"  :disabled="sprint.sprint_trigger_type ==='立即执行'">
                <Option value="之前">之前</Option>
                <Option value="之后">之后</Option>
              </Select>
            </div>
            <div>
              <Select v-model="sprint.hit_not_hit" placeholder="是否触及"style="width: 80px"  :disabled="sprint.sprint_trigger_type ==='立即执行'">
                <Option value="触及">触及</Option>
                <Option value="未触及">未触及</Option>
              </Select>
              <Select v-model="sprint.price_type" placeholder="请选择价格类型" style="width: 80px" :disabled="sprint.sprint_trigger_type ==='立即执行'">
                <Option value="市价" >市价</Option>
                <Option value="指数价" >指数价</Option>
                <Option value="EMA" >EMA</Option>
              </Select>
              <Input v-model="sprint.price"placeholder="触发价格"  style="width: 115px" :disabled="sprint.sprint_trigger_type ==='立即执行'">
              </Input>
            </div>
          </div>
          <div class="modal_form" style="margin-left: 30px">
            <div style="margin-left: 50px">
              <label style="font-weight: 800;letter-spacing:2px;font-size: 16px">距离间隔</label>
            </div>
            <div style="margin-top: 7px">
              <Select v-model="sprint.sprint_perform_interval_type" style="width:100px" >
                <Option value="固定数值" >固定数值</Option>
                <Option value="浮动比例" >浮动比例</Option>
              </Select>
              <Input v-model="sprint.sprint_perform_interval"   style="width: 50px">
              </Input>
              <label style=" margin-right: 10px;" v-show="sprint.sprint_perform_interval_type==='固定数值'">点</label>
              <label style=" margin-right: 10px;" v-show="sprint.sprint_perform_interval_type==='浮动比例'">%</label>
            </div>
          </div>
          <div class="modal_form" style="margin-left: 30px">
            <div style="margin-left: 40px">
              <label style="font-weight: 800;letter-spacing:2px;font-size: 16px">时间间隔</label>
            </div>
            <div style="margin-top: 7px">
              <Input v-model="sprint.sprint_perform_time_interval_display_unmber" style="width: 50px">
              </Input>
              <Select v-model="sprint.sprint_perform_time_interval_display_unit"  style="width:70px" >
                <Option value="秒" >秒</Option>
                <Option value="分" >分</Option>
                <Option value="时" >时</Option>
                <Option value="天" >天</Option>
              </Select>
            </div>
          </div>
          <div class="modal_form" style="margin-left: 30px">
            <div style="margin-left: 70px">
              <label style="font-weight: 800;letter-spacing:2px;font-size: 16px">目标价差</label>
            </div>
            <div style="margin-top: 7px">
              <Select v-model="sprint.target_price_delt_type"  style="width:100px" >
                <Option value="固定数值" >固定数值</Option>
                <Option value="浮动比例" >浮动比例</Option>
              </Select>
              <Input v-model="sprint.target_price_delt"   style="width: 60px">
              </Input>
              <label style=" margin-right: 10px;" v-show="sprint.target_price_delt_type==='固定数值'">点</label>
              <label style=" margin-right: 10px;" v-show="sprint.target_price_delt_type==='浮动比例'">%</label>
            </div>
          </div>
          <div class="modal_form" style="margin-left: 30px">
            <div style="margin-left: 140px">
              <label style="font-weight: 800;letter-spacing:2px;font-size: 16px">冲刺分组</label>
            </div>
            <div style="margin-top: 7px">
              <Select v-model="sprint.group_list" multiple style="width:355px">
                <Option v-for="item in sprint_group" :value="item" :key="item">{{ item }}</Option>
              </Select>
            </div>
          </div>
          <div class="modal_form" style="margin-left: 30px">
            <div style="margin-left: 70px">
              <label style="font-weight: 800;letter-spacing:2px;font-size: 16px">终止价格</label>
            </div>
            <div style="margin-top: 7px">
              <Select v-model="sprint.price_end_type" placeholder="请选择价格类型" style="width: 100px" >
                <Option value="市价" >市价</Option>
                <Option value="指数价" >指数价</Option>
                <Option value="EMA" >EMA</Option>
              </Select>
              <Input v-model="sprint.price_end"placeholder="终止价格"  style="width: 80px"  >
              </Input>
            </div>
          </div>
          <div class="modal_form" style="margin-left: 30px">
            <Button type="primary" size="large" style="margin-top: 10px" @click="insertSprint">保存</Button>
          </div>
        </div>
        <Table :columns="sprint_columns" :data="sprint_data" :row-class-name="rowClassName3" height="600"></Table>
      </Modal>
      <Modal
        v-model="time_triggered_modall"
        class="mycolor_modal"
        :title="time_triggered_modall_title"
        :footer-hide="true"
        :mask-closable = "false"
        width="1530">
        <Form>
          <FormItem  style="margin-bottom: 10px;">
            <label style="font-weight: 800;letter-spacing:2px;font-size: 16px">在</label>
            <DatePicker  type="datetime"  placeholder="时间" v-model="time_triggered.time" ></DatePicker >
            <Select v-model="time_triggered.before_after_time" style="width: 90px"  >
              <Option value="之前">之前</Option>
              <Option value="之后">之后</Option>
            </Select>
            <label style="margin-right: 20px;"></label>
            <Select v-model="time_triggered.hit_not_hit" placeholder="是否触及"style="width: 100px"  >
              <Option value="触及">触及</Option>
              <Option value="未触及">未触及</Option>
            </Select>
            <Select v-model="time_triggered.price_type" placeholder="请选择价格类型" style="width: 100px" >
              <Option value="市价" >市价</Option>
              <Option value="指数价" >指数价</Option>
              <Option value="EMA" >EMA</Option>
            </Select>
            <Input v-model="time_triggered.price"placeholder="触发价格"  style="width: 100px">
            </Input>
            <label style="font-weight: 800;letter-spacing:2px;font-size: 16px">对</label>
            <Select v-model="time_triggered.group_type" placeholder="分组方式(必选)" style="width: 140px">
              <Option value="策略分组">策略分组</Option>
              <Option value="自定义分组">自定义分组</Option>
            </Select>
            <Select v-model="time_triggered.group" placeholder="请选择分组(必选)" style="width: 160px" v-if="time_triggered.group_type !=='策略分组'"                 >
              <Option :value="goup_data" v-for="(goup_data,goup_data_key)  in all_group" :key="goup_data_key">{{goup_data}}</Option>
            </Select>
            <Select v-model="time_triggered.group" placeholder="请选择分组(必选)" style="width: 160px" v-else>
              <Option value="多单" >多单</Option>
              <Option value="空单" >空单</Option>
              <Option value="全部" >全部</Option>
            </Select>
            <Select v-model="time_triggered.position_type" placeholder="请选择持仓方式" style="width: 140px">
              <Option value="已持仓" >已持仓</Option>
              <Option value="未持仓" >未持仓</Option>
              <Option value="全部" >全部</Option>
            </Select>
            <label style="font-weight: 800;letter-spacing:2px;font-size: 16px">执行</label>
            <Select v-model="time_triggered.command_type" placeholder="执行指令" style="width: 120px">
              <Option value="停止" >策略停止</Option>
              <Option value="主动平仓" >主动平仓</Option>
              <Option value="被动平仓" >被动平仓</Option>
            </Select>
            <Button type="primary" size="large" style="margin-left: 20px;" @click="insertTimePrice">保存</Button>
          </FormItem>
        </Form>
        <Table :columns="time_triggered_columns" :data="time_triggered_data" :row-class-name="rowClassName1" height="600"></Table>
      </Modal>
      <Modal
        v-model="auto_start_modall"
        class="mycolor_modal"
        :title="auto_start_modall_title"
        :footer-hide="true"
        :mask-closable = "false"
        width="1200">
        <Form>
          <FormItem  style="margin-bottom: 10px;">
            <label style="font-weight: 800;letter-spacing:2px;font-size: 16px">在</label>
            <DatePicker  type="datetime"  placeholder="时间" v-model="auto_start.time" ></DatePicker >
            <Select v-model="auto_start.before_after_time" style="width: 90px"  >
              <Option value="之前">之前</Option>
              <Option value="之后">之后</Option>
            </Select>
            <label style="font-weight: 800;letter-spacing:2px;font-size: 16px"></label>
            <Select v-model="auto_start.hit_not_hit" placeholder="是否触及"style="width: 100px"  >
              <Option value="触及">触及</Option>
              <Option value="未触及">未触及</Option>
            </Select>

            <Select v-model="auto_start.price_type" placeholder="请选择价格类型" style="width: 100px" >
              <Option value="市价" >市价</Option>
              <Option value="指数价" >指数价</Option>
              <Option value="EMA" >EMA</Option>
            </Select>
            <Input v-model="auto_start.price"placeholder="触发价格"  style="width: 100px">
            </Input>


            <label style="font-weight: 800;letter-spacing:2px;font-size: 16px">启动</label>
            <Select v-model="auto_start.group_type" placeholder="分组方式(必选)" style="width: 140px">
              <Option value="策略分组">策略分组</Option>
              <Option value="自定义分组">自定义分组</Option>
            </Select>

            <Select v-model="auto_start.group" placeholder="请选择分组(必选)" style="width: 160px" v-if="auto_start.group_type !=='策略分组'"                 >
              <Option :value="goup_data" v-for="(goup_data,goup_data_key)  in unrun_group" :key="goup_data_key">{{goup_data}}</Option>
            </Select>
            <Select v-model="auto_start.group" placeholder="请选择分组(必选)" style="width: 160px" v-else>
              <Option value="多单" >多单</Option>
              <Option value="空单" >空单</Option>
              <Option value="全部" >全部</Option>
            </Select>
            <Button type="primary" size="large" style="margin-left: 20px;" @click="insertAutoStart">保存</Button>
          </FormItem>
        </Form>
        <Table :columns="auto_start_columns" :data="auto_start_data" :row-class-name="rowClassName1" height="600"></Table>
      </Modal>
      <Modal
        v-model="point_location_modall"
        :title="point_location_modall_title"
        class="mycolor_modal"
        :footer-hide="true"
        :mask-closable = "false"
        width="1600">
        <Form>
          <FormItem  style="margin-bottom: 10px;">

            <label style="font-weight: 800;letter-spacing:2px;font-size: 16px">触发价格</label>
            <Select v-model="point_location.price_type" placeholder="请选择价格类型" style="width: 100px">
              <Option value="市价" >市价</Option>
              <Option value="指数价" >指数价</Option>
              <Option value="EMA" >EMA</Option>
            </Select>
            <Input v-model="point_location.point" style="width: 100px">
            </Input>
            <label style="font-weight: 800;letter-spacing:2px;font-size: 16px">平移方式</label>
            <Select v-model="point_location.target_price_type" placeholder="平移方式" style="width: 130px" @on-change="target_price_type_change">
              <Option value="固定平移">固定平移</Option>
              <Option value="触发价附近">触发价附近</Option>
            </Select>
            <label style="font-weight: 800;letter-spacing:2px;font-size: 16px" v-show="point_location.target_price_type === '固定平移'">平移点数</label>
            <label style="font-weight: 800;letter-spacing:2px;font-size: 16px" v-show="point_location.target_price_type === '触发价附近'">目标价差</label>
            <Input v-model="point_location.points_translation" style="width: 100px" >
            </Input>
            <label style="font-weight: 800;letter-spacing:2px;font-size: 16px">等待时间</label>
            <Input v-model="point_location.display_number" style="width: 100px">
            </Input>
            <Select v-model="point_location.type"  style="width:70px" >
              <Option value="秒" >秒</Option>
              <Option value="分" >分</Option>
              <Option value="时" >时</Option>
              <Option value="天" >天</Option>
            </Select>
            <label style="font-weight: 800;letter-spacing:2px;font-size: 16px"></label>
            <Select v-model="point_location.command_type" placeholder="分组方式(必选)" style="width: 170px" @on-change="target_price_type_change3">
              <Option value="策略分组">策略分组</Option>
              <Option value="自定义分组">自定义分组</Option>
            </Select>
            <Select v-model="point_location.command" multiple placeholder="请选择分组(必选)" style="width: 170px" v-if="point_location.command_type !=='策略分组'&& point_location.target_price_type === '固定平移'">
              <Option :value="goup_data1" v-for="(goup_data1,goup_data_key1)  in all_group" :key="goup_data_key1">{{goup_data1}}</Option>
            </Select>
            <Select v-model="point_location.command" multiple placeholder="请选择分组(必选)" style="width: 170px" v-if="point_location.command_type !=='策略分组'&& point_location.target_price_type === '触发价附近'">
              <Option :value="goup_data2" v-for="(goup_data2,goup_data_key2)  in point_location_group" :key="goup_data_key2">{{goup_data2}}</Option>
            </Select>
            <Select v-model="point_location.command" multiple placeholder="请选择分组(必选)" style="width: 170px" v-if="point_location.command_type ==='策略分组' && point_location.target_price_type === '固定平移'">
              <Option value="多单" >多单</Option>
              <Option value="空单" >空单</Option>
              <Option value="全部" >全部</Option>
            </Select>
            <Select v-model="point_location.command" multiple placeholder="请选择分组(必选)" style="width: 170px" v-if="point_location.command_type ==='策略分组' && point_location.target_price_type === '触发价附近'">
              <Option value="多单" >多单</Option>
              <Option value="空单" >空单</Option>
            </Select>
            <Select v-model="point_location.inposition_type" placeholder="请选择持仓方式" style="width: 140px" v-if="point_location.target_price_type === '固定平移'">
              <Option value="已持仓" >已持仓</Option>
              <Option value="未持仓" >未持仓</Option>
              <Option value="全部" >全部</Option>
            </Select>
            <Select v-model="point_location.inposition_type" placeholder="请选择持仓方式" style="width: 140px" v-if="point_location.target_price_type === '触发价附近'">
              <Option value="未持仓" >未持仓</Option>
            </Select>
            <Button type="primary" size="large" style="margin-left: 20px;" @click="insertPointLocation">保存</Button>
          </FormItem>
        </Form>
        <Table :columns="point_location_columns" :data="point_location_data" :row-class-name="rowClassName2" height="600"></Table>
      </Modal>



      <Modal
        v-model="update_point_location_modall"
        :title="update_point_location_modall_title"
        :mask-closable = "false"
        @on-ok ="update_point_location_save"
        @on-cancel ="update_point_location_cancel"
        :loading ='true'
        width="440">
        <div>
          <Form>
            <FormItem label="id" :label-width="120" style="margin-bottom: 10px;">
              <Input v-model="update_point_location.strategy_id" style="width: 240px" disabled="disabled"></Input>
            </FormItem>
            <FormItem label="触发价格" :label-width="120" style="margin-bottom: 10px;" >
              <Select v-model="update_point_location.price_type" placeholder="请选择价格类型" style="width: 120px">
                <Option value="市价" >市价</Option>
                <Option value="指数价" >指数价</Option>
                <Option value="EMA" >EMA</Option>
              </Select>
              <Input v-model="update_point_location.point" style="width: 120px">
              </Input>
            </FormItem>
            <FormItem label="平移方式" :label-width="120" style="margin-bottom: 10px;">
              <Select v-model="update_point_location.target_price_type" placeholder="平移方式" style="width: 240px" @on-change="target_price_type_change2">
                <Option value="固定平移">固定平移</Option>
                <Option value="触发价附近">触发价附近</Option>
              </Select>
            </FormItem>
            <FormItem label="平移点数" :label-width="120" style="margin-bottom: 10px;" v-if="update_point_location.target_price_type=== '固定平移'">
              <Input v-model="update_point_location.points_translation" style="width: 240px">
              </Input>
            </FormItem>
            <FormItem label="目标价差" :label-width="120" style="margin-bottom: 10px;" v-if="update_point_location.target_price_type=== '触发价附近'">
              <Input v-model="update_point_location.points_translation" style="width: 240px">
              </Input>
            </FormItem>
            <FormItem label="等待时间" :label-width="120" style="margin-bottom: 10px;">
              <Input v-model="update_point_location.display_number" style="width: 150px">
              </Input>
              <Select v-model="update_point_location.display_unit"  style="width:90px" >
                <Option value="秒" >秒</Option>
                <Option value="分" >分</Option>
                <Option value="时" >时</Option>
                <Option value="天" >天</Option>
              </Select>
            </FormItem>
            <FormItem label="组号" :label-width="120" style="margin-bottom: 10px;">
              <Select v-model="update_point_location.command_type" placeholder="分组方式(必选)" style="width: 120px" @on-change="target_price_type_change4">
                <Option value="策略分组">策略分组</Option>
                <Option value="自定义分组">自定义分组</Option>
              </Select>
              <!--              <Select v-model="update_point_location.command" placeholder="请选择分组(必选)" style="width: 120px" v-if="update_point_location.command_type !=='策略分组'"                 >-->
              <!--                <Option :value="goup_data" v-for="(goup_data,goup_data_key)  in all_group" :key="goup_data_key">{{goup_data}}</Option>-->
              <!--              </Select>-->
              <!--              <Select v-model="update_point_location.command" placeholder="请选择分组(必选)" style="width: 120px" v-else>-->
              <!--                <Option value="多单" >多单</Option>-->
              <!--                <Option value="空单" >空单</Option>-->
              <!--                <Option value="全部" >全部</Option>-->
              <!--              </Select>-->

              <Select v-model="update_point_location.command" multiple placeholder="请选择分组(必选)" style="width: 120px" v-if="update_point_location.command_type !=='策略分组'&& update_point_location.target_price_type === '固定平移'">
                <Option :value="goup_data1" v-for="(goup_data1,goup_data_key1)  in all_group" :key="goup_data_key1">{{goup_data1}}</Option>
              </Select>
              <Select v-model="update_point_location.command" multiple placeholder="请选择分组(必选)" style="width: 120px" v-if="update_point_location.command_type !=='策略分组'&& update_point_location.target_price_type === '触发价附近'">
                <Option :value="goup_data2" v-for="(goup_data2,goup_data_key2)  in point_location_group" :key="goup_data_key2">{{goup_data2}}</Option>
              </Select>
              <Select v-model="update_point_location.command" multiple placeholder="请选择分组(必选)" style="width: 120px" v-if="update_point_location.command_type ==='策略分组' && update_point_location.target_price_type === '固定平移'">
                <Option value="多单" >多单</Option>
                <Option value="空单" >空单</Option>
                <Option value="全部" >全部</Option>
              </Select>
              <Select v-model="update_point_location.command" multiple placeholder="请选择分组(必选)" style="width: 120px" v-if="update_point_location.command_type ==='策略分组' && update_point_location.target_price_type === '触发价附近'">
                <Option value="多单" >多单</Option>
                <Option value="空单" >空单</Option>
              </Select>
            </FormItem>
            <FormItem label="持仓类型" :label-width="120" style="margin-bottom: 10px;">
              <Select v-model="update_point_location.inposition_type" placeholder="请选择持仓方式" style="width: 240px" v-if="update_point_location.target_price_type === '固定平移'">
                <Option value="已持仓" >已持仓</Option>
                <Option value="未持仓" >未持仓</Option>
                <Option value="全部" >全部</Option>
              </Select>
              <Select v-model="update_point_location.inposition_type" placeholder="请选择持仓方式" style="width: 240px" v-if="update_point_location.target_price_type === '触发价附近'">
                <Option value="未持仓" >未持仓</Option>
              </Select>
            </FormItem>
          </Form>
        </div><!--注册界面组件-->
      </Modal>
      <Modal
        v-model="update_time_triggered_modall"
        :title="update_time_triggered_modall_title"
        :mask-closable = "false"
        @on-ok ="update_time_triggered_save"
        @on-cancel ="update_time_triggered_cancel"
        :loading ='true'
        width="560">
        <div>
          <Form>
            <FormItem label="id" :label-width="120" style="margin-bottom: 10px;">
              <Input v-model="update_time_triggered.strategy_id" style="width: 360px" disabled="disabled"></Input>
            </FormItem>
            <FormItem label="终止时间" :label-width="120" style="margin-bottom: 10px;">
              <DatePicker  type="datetime" style="width: 180px" v-model="update_time_triggered.time"></DatePicker >
              <Select v-model="update_time_triggered.before_after_time" style="width: 175px">
                <Option value="之前">之前</Option>
                <Option value="之后">之后</Option>
              </Select>
            </FormItem>
            <FormItem label="触发价格" :label-width="120" style="margin-bottom: 10px;" >
              <Select v-model="update_time_triggered.price_type" placeholder="请选择价格类型" style="width: 120px">
                <Option value="市价" >市价</Option>
                <Option value="指数价" >指数价</Option>
                <Option value="EMA" >EMA</Option>
              </Select>
              <Input v-model="update_time_triggered.price" style="width: 110px">
              </Input>
              <Select v-model="update_time_triggered.hit_not_hit" placeholder="是否触及"style="width: 120px" >
                <Option value="触及">触及</Option>
                <Option value="未触及">未触及</Option>
              </Select>


            </FormItem>
            <FormItem label="组号" :label-width="120" style="margin-bottom: 10px;">
              <Select v-model="update_time_triggered.group_type" placeholder="分组方式(必选)" style="width: 110px">
                <Option value="策略分组">策略分组</Option>
                <Option value="自定义分组">自定义分组</Option>
              </Select>
              <Select v-model="update_time_triggered.group" placeholder="分组(必选)" style="width: 140px" v-if="update_time_triggered.group_type !=='策略分组'"                 >
                <Option :value="goup_data" v-for="(goup_data,goup_data_key)  in all_group" :key="goup_data_key">{{goup_data}}</Option>
              </Select>
              <Select v-model="update_time_triggered.group" placeholder="分组(必选)" style="width: 140px" v-else>
                <Option value="多单" >多单</Option>
                <Option value="空单" >空单</Option>
                <Option value="全部" >全部</Option>
              </Select>
              <Select v-model="update_time_triggered.position_type" placeholder="持仓方式" style="width: 100px">
                <Option value="已持仓" >已持仓</Option>
                <Option value="未持仓" >未持仓</Option>
                <Option value="全部" >全部</Option>
              </Select>
            </FormItem>
            <FormItem label="执行指令" :label-width="120" style="margin-bottom: 10px;">
              <Select v-model="update_time_triggered.command_type" placeholder="执行指令" style="width: 360px">
                <Option value="停止" >停止</Option>
                <Option value="主动平仓" >主动平仓</Option>
                <Option value="被动平仓" >被动平仓</Option>
              </Select>
            </FormItem>
          </Form>
        </div><!--注册界面组件-->
      </Modal>
      <Modal
        v-model="update_auto_start_modall"
        :title="update_auto_start_modall_title"
        :mask-closable = "false"
        @on-ok ="update_auto_start_save"
        @on-cancel ="update_auto_start_cancel"
        :loading ='true'
        width="560">
        <div>
          <Form>
            <FormItem label="id" :label-width="120" style="margin-bottom: 10px;">
              <Input v-model="update_auto_start.strategy_id" style="width: 360px" disabled="disabled"></Input>
            </FormItem>
            <FormItem label="时间" :label-width="120" style="margin-bottom: 10px;" >
              <DatePicker  type="datetime" style="width: 180px" v-model="update_auto_start.time"></DatePicker >
              <Select v-model="update_auto_start.before_after_time" style="width: 175px">
                <Option value="之前">之前</Option>
                <Option value="之后">之后</Option>
              </Select>
            </FormItem>
            <FormItem label="触发价格" :label-width="120" style="margin-bottom: 10px;" >
              <Select v-model="update_auto_start.price_type" placeholder="请选择价格类型" style="width: 120px">
                <Option value="市价" >市价</Option>
                <Option value="指数价" >指数价</Option>
                <Option value="EMA" >EMA</Option>
              </Select>
              <Input v-model="update_auto_start.price" style="width: 110px">
              </Input>
              <Select v-model="update_auto_start.hit_not_hit" placeholder="是否触及"style="width: 120px" >
                <Option value="触及">触及</Option>
                <Option value="未触及">未触及</Option>
              </Select>
            </FormItem>
            <FormItem label="组号" :label-width="120" style="margin-bottom: 10px;">
              <Select v-model="update_auto_start.group_type" placeholder="分组方式(必选)" style="width: 175px">
                <Option value="策略分组">策略分组</Option>
                <Option value="自定义分组">自定义分组</Option>
              </Select>
              <Select v-model="update_auto_start.group" placeholder="分组(必选)" style="width: 180px" v-if="update_auto_start.group_type !=='策略分组'"                 >
                <Option :value="goup_data" v-for="(goup_data,goup_data_key)  in unrun_group" :key="goup_data_key">{{goup_data}}</Option>
              </Select>
              <Select v-model="update_auto_start.group" placeholder="分组(必选)" style="width: 180px" v-else>
                <Option value="多单" >多单</Option>
                <Option value="空单" >空单</Option>
                <Option value="全部" >全部</Option>
              </Select>
            </FormItem>
          </Form>
        </div><!--注册界面组件-->
      </Modal>
      <Modal
        v-model="update_sprint_modall"
        :title="update_sprint_modall_title"
        :mask-closable = "false"
        @on-ok ="updateSprint_save"
        @on-cancel ="updateSprint_cancel"
        :loading ='true'
        width="560">
        <div>
          <Form>
            <FormItem label="id" :label-width="120" style="margin-bottom: 10px;">
              <Input v-model="update_sprint.sprint_strategy_id" style="width: 360px" disabled="disabled"></Input>
            </FormItem>
            <FormItem label="执行方式" :label-width="120" style="margin-bottom: 10px;">
              <Select v-model="update_sprint.sprint_trigger_type" placeholder="请选择类型" style="width: 360px" :disabled="update_sprint.status ==='冲刺中'">
                <Option value="立即执行" >立即执行</Option>
                <Option value="价格时间" >价格时间</Option>
              </Select>
            </FormItem>
            <FormItem label="时间" :label-width="120" style="margin-bottom: 10px;" v-show="update_sprint.sprint_trigger_type=== '价格时间'">
              <DatePicker  type="datetime" style="width: 180px" v-model="update_sprint.time" :disabled="update_sprint.status ==='冲刺中'"></DatePicker >
              <Select v-model="update_sprint.before_after_time" style="width: 175px" :disabled="update_sprint.status ==='冲刺中'">
                <Option value="之前">之前</Option>
                <Option value="之后">之后</Option>
              </Select>
            </FormItem>
            <FormItem label="触发价格" :label-width="120" style="margin-bottom: 10px;" v-show="update_sprint.sprint_trigger_type=== '价格时间'">
              <Select v-model="update_sprint.price_type" placeholder="请选择价格类型" style="width: 120px" :disabled="update_sprint.status ==='冲刺中'">
                <Option value="市价" >市价</Option>
                <Option value="指数价" >指数价</Option>
                <Option value="EMA" >EMA</Option>
              </Select>
              <Select v-model="update_sprint.hit_not_hit" placeholder="是否触及"style="width: 120px" :disabled="update_sprint.status ==='冲刺中'">
                <Option value="触及">触及</Option>
                <Option value="未触及">未触及</Option>
              </Select>
              <Input v-model="update_sprint.price" style="width: 110px" :disabled="update_sprint.status ==='冲刺中'">
              </Input>

            </FormItem>
            <Divider :dashed="true"/>
            <FormItem label="距离间隔" :label-width="120" style="margin-bottom: 10px;">
              <Select v-model="update_sprint.sprint_perform_interval_type" style="width:180px" >
                <Option value="固定数值" >固定数值</Option>
                <Option value="浮动比例" >浮动比例</Option>
              </Select>
              <Input v-model="update_sprint.sprint_perform_interval"   style="width: 180px">
              </Input>
              <label style=" margin-right: 10px;" v-show="update_sprint.sprint_perform_interval_type==='固定数值'">点</label>
              <label style=" margin-right: 10px;" v-show="update_sprint.sprint_perform_interval_type==='浮动比例'">%</label>
            </FormItem>
            <FormItem label="时间间隔" :label-width="120" style="margin-bottom: 10px;">
              <Input v-model="update_sprint.sprint_perform_time_interval_display_unmber" style="width: 180px">
              </Input>
              <Select v-model="update_sprint.sprint_perform_time_interval_display_unit"  style="width:180px" >
                <Option value="秒" >秒</Option>
                <Option value="分" >分</Option>
                <Option value="时" >时</Option>
                <Option value="天" >天</Option>
              </Select>
            </FormItem>
            <Divider :dashed="true"/>
            <FormItem label="目标价差" :label-width="120" style="margin-bottom: 10px;">
              <Select v-model="update_sprint.target_price_delt_type"  style="width:180px" >
                <Option value="固定数值" >固定数值</Option>
                <Option value="浮动比例" >浮动比例</Option>
              </Select>
              <Input v-model="update_sprint.target_price_delt"   style="width: 180px">
              </Input>
              <label style=" margin-right: 10px;" v-show="update_sprint.target_price_delt_type==='固定数值'">点</label>
              <label style=" margin-right: 10px;" v-show="update_sprint.target_price_delt_type==='浮动比例'">%</label>
            </FormItem>
            <FormItem label="终止价格" :label-width="120" style="margin-bottom: 10px;">
              <Select v-model="update_sprint.price_end_type" placeholder="请选择价格类型" style="width: 180px" >
                <Option value="市价" >市价</Option>
                <Option value="指数价" >指数价</Option>
                <Option value="EMA" >EMA</Option>
              </Select>
              <Input v-model="update_sprint.price_end"placeholder="终止价格"  style="width: 180px"  >
              </Input>
            </FormItem>
            <FormItem label="冲刺分组" :label-width="120" style="margin-bottom: 10px;">
              <Input v-model="update_sprint.group_list" style="width: 360px" disabled="disabled"></Input>
            </FormItem>
          </Form>
        </div><!--注册界面组件-->
      </Modal>

      <Modal
        v-model="sprint_delete_modall"
        ok-text="确定"
        cancel-text="取消"
        :mask-closable = "false"
        :loading ='true'
        @on-ok="delete_Sprint()"
      >
        <p>确认要删除吗？</p>
      </Modal>
      <Modal
        v-model="auto_start_delete_modall"
        ok-text="确定"
        cancel-text="取消"
        :mask-closable = "false"
        :loading ='true'
        @on-ok="delete_Autorun()"
      >
        <p>确认要删除吗？</p>
      </Modal>
      <Modal
        v-model="time_triggered_delete_modall"
        ok-text="确定"
        cancel-text="取消"
        :mask-closable = "false"
        :loading ='true'
        @on-ok="delete_time_triggered()"
      >
        <p>确认要删除吗？</p>
      </Modal>
      <Modal
        v-model="point_location_delete_modall"
        ok-text="确定"
        cancel-text="取消"
        :mask-closable = "false"
        :loading ='true'
        @on-ok="delete_point_location()"
      >
        <p>确认要删除吗？</p>
      </Modal>
    </div>
  </div>
</template>


<script>
  import {
    updateRisk,
    synchronous,
    getListTimePrice,
    insertTimePrice,
    deleteTimePrice,
    getListPointTranslation,
    insertPointTranslation,
    deletePointTranslation,
    updatePointTranslation,
    updateTimePrice,
    insertAutoleave,
    getListAutoleave,
    deleteAutoleave,
    updateAutoleave,
    insertAutorun,
    getListAutorun,
    deleteAutorun,
    updateAutorun,
    insertSprint,
    getListSprint,
    deleteSprint,
    updateSprint,
    updateProfitLossCal,
  } from '@/api/trade'
  import {
    TimeToDate,
    isNumberAndNone,
    isNumberAndPositive,
    isPositiveInteger,
  } from '@/libs/tools'
  import { mapGetters,mapMutations,mapActions } from 'vuex'
  import Trade_main from "../trade_main/trade_main";
    export default {
        name: "trade_header",
      components: {Trade_main},
      data(){
        return{
          contract_list:[],//合约数组
          contractSelected: '',
          client_list:[],
          clientSelected: '',
          client_info:{
            basic:{
              static:'',
              buy_volume:'',
              sell_volume:'',
              profit_real:'',
              profit_unreal:'',
              cny:'',
              lowest_net_worth:'',
            }, //基本信息
            risk:{
              end_down:'',
              end_down_type:'',
              end_down_price_type:'',
              end_up:'',
              end_up_type:'',
              end_up_price_type:'',
              end_time:'',
            },  //风险控制
            profit_loss_cal_status_unrun:false,
            client_info:[], //盈亏
            account_status:'',
          },//账号信息
          price:{
            price_now:'',//市价格
            price_index:'',//指数价格
            price_ema:'',//ema价格
            price_of_stop_profit_and_stop_loss:'',//系统使用的价格
          },
          trade_main_modal:false,//交易区的显隐
          updata_risk:{
            end_down:'',
            end_up:'',
            end_time:'',
            end_down_type:'被动',
            end_down_price_type:'市价',
            end_up_type:'被动',
            end_up_price_type:'市价',
            end_time_type:'被动',
          },
          end_time:'',
          risk_modall:false,
          risk_modall_title:'',
          synchronous_modall:false,
          sprint_modall:false,
          sprint_modall_title:"冲刺",
          sprint:{
            sprint_strategy_id:'',
            client_name:'',
            contract_code:'',
            sprint_trigger_type:'价格时间',
            time:'',
            price_type:'市价',
            hit_not_hit:'触及',
            before_after_time:'之后',
            group_list:'',
            target_price_delt:'',
            target_price_delt_type:'固定数值',
            sprint_perform_interval:'',
            sprint_perform_interval_type:'固定数值',
            sprint_perform_time_interval:'',
            sprint_perform_time_interval_display_unmber:'',
            sprint_perform_time_interval_display_unit:'秒',
            price_end:'',
            price_end_type:'市价',
          },
          update_sprint:{
            sprint_strategy_id:'',
            client_name:'',
            contract_code:'',
            sprint_trigger_type:'价格时间',
            time:'',
            price_type:'市价',
            hit_not_hit:'触及',
            before_after_time:'之后',
            group_list:'',
            target_price_delt:'',
            target_price_delt_type:'固定数值',
            sprint_perform_interval:'',
            sprint_perform_interval_type:'固定数值',
            sprint_perform_time_interval:'',
            sprint_perform_time_interval_display_unmber:'',
            sprint_perform_time_interval_display_unit:'秒',
            status:'',
            price_end:'',
            price_end_type:'市价',
          },
          sprint_group: [],
          sprint_columns:[
            {
              title: 'id',
              align: 'center',
              key: 'sprint_strategy_id',
              width:'95',
            },
            {
              title: '时间条件',
              align: 'center',
              width:'200',
              render: (h, params) => {
                if(params.row.sprint_trigger_type === '价格时间'){
                  return h('span',{
                  },params.row.time +  params.row.before_after_time)
                }else if(params.row.sprint_trigger_type === '立即执行'){
                  return h('span',{
                  },'立即执行')
                }

              },
            },
            {
              title: '是否触及',
              align: 'center',
              width:'95',
              render: (h, params) => {
                if(params.row.sprint_trigger_type === '价格时间'){
                  return h('span',{
                  }, params.row.hit_not_hit)
                }else if(params.row.sprint_trigger_type === '立即执行'){
                  return h('span',{
                  },'')
                }
              },
            },
            {
              title: '价格条件',
              align: 'center',
              width:'140',
              render: (h, params) => {
                if(params.row.sprint_trigger_type === '价格时间'){
                  return h('span',{
                  }, params.row.price+'('+params.row.price_type+')')
                }else if(params.row.sprint_trigger_type === '立即执行'){
                  return h('span',{
                  },'立即执行')
                }
              },
            },
            {
              title: '冲刺间隔',
              align: 'center',
              width:'150',
              render: (h, params) => {
                if(params.row.sprint_perform_interval_type === '固定数值'){
                  return h('span',{
                  },params.row.sprint_perform_interval + '点')
                }else if(params.row.sprint_perform_interval_type === '浮动比例'){
                  return h('span',{
                  },params.row.sprint_perform_interval + '%')
                }
              },
            },
            {
              title: '时间间隔',
              align: 'center',
              key: 'time_interval',
              width:'180',
              render: (h, params) => {
                return h('span',{

                },params.row.sprint_perform_time_interval_display_unmber + params.row.sprint_perform_time_interval_display_unit)},
            },
            {
              title: '目标价差',
              align: 'center',
              width:'150',
              render: (h, params) => {
                if(params.row.target_price_delt_type === '固定数值'){
                  return h('span',{
                  },params.row.target_price_delt + '点')
                }else if(params.row.target_price_delt_type === '浮动比例'){
                  return h('span',{
                  },params.row.target_price_delt + '%')
                }
              },
            },
            {
              title: '组号',
              align: 'center',
              key: 'group_list',
              width:'350',
            },
            {
              title: '终止价格',
              align: 'center',
              render: (h, params) => {
                return h('span',{
                },params.row.price_end + '('+params.row.price_end_type +')')},
            },
            {
              title: '状态',
              align: 'center',
              key: 'status',
              width:'95',
            },
            {
              title: '操作',
              key: 'operation',
              fixed: 'right',
              render: (h, params) => {
                return h('div', [
                  h('Button', {
                    props: {
                      type: 'text',
                      size: 'small'
                    },
                    on:{
                      click: () => {
                        console.log(params.row)
                        this.update_sprint_modall = true;
                        this.update_sprint =  JSON.parse(JSON.stringify(params.row));
                      }
                    }
                  }, '编辑'),
                  h('Button', {
                    props: {
                      type: 'text',
                      size: 'small'
                    },
                    on:{
                      click: () => {
                        this.sprint_delete_id = params.row.sprint_strategy_id;
                        this.sprint_delete_modall = true;
                      }
                    }
                  }, '删除')
                ]);
              }
            },
          ],
          sprint_data:[],
          sprint_delete_modall:false,
          sprint_delete_id:'',
          update_sprint_modall:false,
          update_sprint_modall_title:'冲刺',
          point_location_modall:false,
          point_location_modall_title:'自动平移',
          point_location:{
            price_type:'市价',
            point:'',
            target_price_type:'固定平移',
            points_translation:'',
            display_number:'',
            waiting_time:'60',
            type:'秒',
            command_type:'自定义分组',
            command:'',
            inposition_type:'未持仓',
          },
          update_point_location:{
            price_type:'市价',
            point:'',
            target_price_type:'固定平移',
            points_translation:'',
            display_number:'',
            waiting_time:'60',
            type:'秒',
            command_type:'自定义分组',
            command:'',
            inposition_type:'未持仓',
          },
          point_location_columns:[
            {
              title: 'id',
              align: 'center',
              key: 'strategy_id',
              width:'95',
            },
            {
              title: '触发价格',
              align: 'center',
              key: 'point',
              render: (h, params) => {
                return h('span',{
                },params.row.point+'('+params.row.price_type+')')},
            },
            {
              title: '平移命令',
              align: 'center',
              key: 'target_price_type',
              render: (h, params) => {
                return h('span',{
                },params.row.target_price_type+':'+params.row.points_translation)},
            },
            {
              title: '等待时间',
              align: 'center',
              key: 'waiting_time',
              render: (h, params) => {
                return h('span',{

                },params.row.display_number + params.row.display_unit)},
            },
            {
              title: '命令类型',
              align: 'center',
              key: 'command_type'
            },
            {
              title: '组号',
              align: 'center',
              key: 'command'
            },
            {
              title: '持仓类型',
              align: 'center',
              key: 'inposition_type'
            },

            {
              title: '操作',
              key: 'operation',
              fixed: 'right',
              render: (h, params) => {
                return h('div', [
                  h('Button', {
                    props: {
                      type: 'text',
                      size: 'small'
                    },
                    on:{
                      click: () => {
                        console.log(params.row)
                        this.update_point_location_modall = true;
                        this.update_point_location =  JSON.parse(JSON.stringify(params.row));
                        this.update_point_location.command = this.update_point_location.command.split(',')
                      }
                    }
                  }, '编辑'),
                  h('Button', {
                    props: {
                      type: 'text',
                      size: 'small'
                    },
                    on:{
                      click: () => {
                        this.point_location_delete_id = params.row.strategy_id;
                        this.point_location_delete_modall = true;
                      }
                    }
                  }, '删除')
                ]);
              }
            },
          ],
          point_location_data:[],
          point_location_delete_modall:false,
          point_location_delete_id:'',
          time_triggered_modall:false,
          time_triggered_modall_title:'自动离场',
          time_triggered:{
            strategy_id:'',
            time:'',
            price:'',
            price_type:'市价',
            hit_not_hit:'触及',
            group_type:'自定义分组',
            group:'',
            before_after_time: '之后',
            position_type:'未持仓',
            command_type:'停止',
          },
          update_time_triggered:{
            strategy_id:'',
            time_price_or_price_time:'时间价格',
            time:'',
            price:'',
            price_type:'市价',
            price_been_notbeen:'',
            group_type:'自定义分组',
            group:'',
            before_after_time: '之后',
            position_type:'未持仓',
            command_type:'停止',
            first_type:'',
          },
          time_triggered_columns:[
            {
              title: 'id',
              key: 'strategy_id',
              align: 'center',
              width:'80',
            },
            {
              title: '时间条件',
              align: 'center',
              render: (h, params) => {
                return h('span',{
                },params.row.time +  params.row.before_after_time)
              },
            },
            {
              title: '是否触及',
              align: 'center',
              key: 'hit_not_hit',
            },
            {
              title: '价格条件',
              align: 'center',
              render: (h, params) => {
                return h('span',{
                },params.row.price+'('+params.row.price_type+')')

              },
            },
            {
              title: '组号',
              align: 'center',
              key: 'group',
            },
            {
              title: '是否持仓',
              align: 'center',
              key: 'position_type',
            },
            {
              title: '离场方式',
              align: 'center',
              key: 'command_type',
            },
            {
              title: '操作',
              key: 'operation',
              fixed: 'right',
              width:'140',
              render: (h, params) => {
                return h('div', [
                  h('Button', {
                    props: {
                      type: 'text',
                      size: 'small'
                    },
                    on:{
                      click: () => {
                        console.log(params.row)
                        this.update_time_triggered_modall = true;
                        this.update_time_triggered =  JSON.parse(JSON.stringify(params.row));
                      }
                    }
                  }, '编辑'),
                  h('Button', {
                    props: {
                      type: 'text',
                      size: 'small'
                    },
                    on:{
                      click: () => {
                        this.time_triggered_delete_modall = true;
                        this.time_triggered_delete_id = params.row.strategy_id;
                      }
                    }
                  }, '删除')
                ]);
              }
            },
          ],
          time_triggered_data:[],
          time_triggered_delete_modall:false,
          time_triggered_delete_id:'',
          run_group:[],
          unrun_group:[],
          all_group:[],
          compare_price:'',//比较的价格
          update_point_location_modall:false,
          update_point_location_modall_title:'编辑自动平移',
          update_time_triggered_modall:false,
          update_time_triggered_modall_title:'编辑自动离场',
          auto_start_modall:false,
          auto_start_modall_title:'自动启动',
          auto_start:{
            strategy_id:'',
            time_price_or_price_time:'时间价格',
            time:'',
            price:'',
            price_type:'市价',
            before_after_time:'之后',
            hit_not_hit:'触及',
            group_type:'自定义分组',
            group:'',
          },
          auto_start_columns:[
            {
              title: 'id',
              key: 'strategy_id',
              align: 'center',
              width:'80',
            },
            {
              title: '时间条件',
              align: 'center',
              render: (h, params) => {
                return h('span',{
                },params.row.time +  params.row.before_after_time)
              },
            },
            {
              title: '是否触及',
              align: 'center',
              key: 'hit_not_hit',
            },
            {
              title: '价格条件',
              align: 'center',
              render: (h, params) => {
                return h('span',{
                }, params.row.price+'('+params.row.price_type+')')
              },
            },
            {
              title: '组号',
              align: 'center',
              key: 'group',
            },
            {
              title: '操作',
              key: 'operation',
              fixed: 'right',
              width:'140',
              render: (h, params) => {
                return h('div', [
                  h('Button', {
                    props: {
                      type: 'text',
                      size: 'small'
                    },
                    on:{
                      click: () => {
                        console.log(params.row)
                        this.update_auto_start_modall = true;
                        this.update_auto_start =  JSON.parse(JSON.stringify(params.row));
                      }
                    }
                  }, '编辑'),
                  h('Button', {
                    props: {
                      type: 'text',
                      size: 'small'
                    },
                    on:{
                      click: () => {
                        this.auto_start_delete_modall = true;
                        this.auto_start_delete_id = params.row.strategy_id;
                      }
                    }
                  }, '删除')
                ]);
              }
            },
          ],
          auto_start_data:[],
          auto_start_delete_modall:false,
          auto_start_delete_id:'',
          update_auto_start_modall:false,
          update_auto_start_modall_title:'编辑自动启动',
          update_auto_start:{
            strategy_id:'',
            time_price_or_price_time:'时间价格',
            time:'',
            price:'',
            price_type:'市价',
            before_after_time:'之后',
            hit_not_hit:'触及',
            group_type:'自定义分组',
            group:'',
          },
          max_profit_and_loss_columns:[
            {
              title: '$',
              key: 'name'
            },
            {
              title: '直涨',
              key: 'c1'
            },
            {
              title: '循涨',
              key: 'c2'
            },
            {
              title: '直跌',
              key: 'c3'
            },
            {
              title: '循跌',
              key: 'c4'
            },
          ],
          max_profit_and_loss_data:[
            {
              name:"多单",
              c1:0.1,
              c2:2,
              c3:-1,
              c4:1,
            },
            {
              name:"空单",
              c1:0.1,
              c2:2,
              c3:-1,
              c4:1,
            },
            {
              name:"账户",
              c1:0.1,
              c2:2,
              c3:-1,
              c4:1,
            }
          ],
          flag :false,//点击之后设置按钮不可使用
          flag_setTimeout:'',//点击之后设置按钮不可使用
          point_location_group:[],
        }
      },
      created(){
        this.client_list =[];
        this.clientSelected = '';
        if(this.get_client() !==''){
          this.clientSelected = this.get_client();
        }
        if(this.get_client_list().length !==0){
          this.client_list = this.get_client_list();
          if(this.clientSelected == ""){
            this.clientSelected = this.client_list[0];
          }
        }
        if(this.get_client_info().basic!==undefined){
          this.client_info = this.get_client_info();
        }
        if(this.clientSelected == ""){
          this.get_Client2();
        }
      },
      methods: {
        ...mapGetters([
          'get_client',
          'get_contract',
          'get_client_list',
          'get_contract_list',
          'get_client_info',
          'get_price',
          'get_run_group',
          'get_unrun_group',
          'get_all_group',
        ]),
        ...mapMutations([
          'set_run_select_Ids',
          'set_unrun_select_Ids',
          'set_run_group',
          'set_unrun_group',
          'set_all_group',
          'set_data_group_id_run',
          'set_data_group_id_unrun',
          'set_client',
          'set_base_paramter',
          'set_batch_paramter',
          'set_contract',
          'set_list_strategy',
          'set_list_strategy_unrun',
          'set_list_strategy_run',
        ]),
        ...mapActions([
          'handleLogOut',
          'getcontract',
          'getClient',
          'getClientInfoPro',
          'getListStrategypro',
          'getBatchParamter',
          'getBaseParamter',
          'stopClientInfoPro',
        ]),
        //获取用户ID
        get_Client2() {
          this.getClient({}).then(res => {
            console.log(res)
          }).catch(err => {
            console.log(err)
          })
        },
        //获取合约
        get_contract2() {
          let client = this.clientSelected; //用户ID（用户名）
          this.getcontract({client}).then(res => {
            console.log(res)
          }).catch(err => {
            console.log(err)
          })
        },
        //获取用户基本信息、风险控制
        get_ClientInfo2() {
          let client = this.clientSelected; //用户ID（用户名）
          let contract = this.contractSelected;//合约名称
          if(client !== '' && contract !== '' && contract!== undefined){
            this.getClientInfoPro({client, contract}).then(res => {
              console.log(res);
            }).catch(err => {
              console.log(err)
              this.clear_client_info();
            })
          }
        },
        //清空基本信息，风险控制
        clear_client_info() {
          this.client_info = {
            basic: {
              static: '',
              buy_volume: '',
              sell_volume: '',
              profit_real: '',
              cny: '',
              profit_unreal: '',
              lowest_net_worth: '',
            }, //基本信息
            risk: {
              end_down: '',
              end_up: '',
              end_time: '',
            },  //风险控制
          };
        },
        //关闭交易区
        close_modal({close}) {
          this.trade_main_modal = close
        },
        //修改风险控制
        update_risk(name) {
          this.updata_risk.end_down = this.client_info.risk.end_down;
          this.updata_risk.end_up = this.client_info.risk.end_up;
          this.price = this.get_price();
          if (name === '下终止') {
            this.risk_modall_title = '修改下终止';
            this.updata_risk.end_down = this.client_info.risk.end_down;
            this.updata_risk.end_down_type = this.client_info.risk.end_down_type;
            this.updata_risk.end_down_price_type = this.client_info.risk.end_down_price_type;
          } else if (name === '上终止') {
            this.risk_modall_title = '修改上终止';
            this.updata_risk.end_up = this.client_info.risk.end_up;
            this.updata_risk.end_up_type = this.client_info.risk.end_up_type;
            this.updata_risk.end_up_price_type = this.client_info.risk.end_up_price_type;
          } else if (name == '止损时间') {
            this.risk_modall_title = '修改止损时间';
            this.updata_risk.end_time = this.end_time;
            this.updata_risk.end_time_type = this.client_info.risk.end_time_type;
          }
          this.risk_modall = true;
        },
        risk_save() {
          let params = {};
          if (this.risk_modall_title == '修改下终止') {
            params = {
              client_name: this.clientSelected,
              contract: this.contractSelected,
              value: this.updata_risk.end_down == '' ? "None" : this.updata_risk.end_down,
              end_down_type: this.updata_risk.end_down_type,
              end_down_price_type: this.updata_risk.end_down_price_type,
              type: 'end_down'
            };
            updateRisk(params).then(res => {
              this.risk_modall = false;
              if(res.status === 502){
                this.$Message.error("发生502，请核查下终止");
                return;
              }
              this.$Message.success("修改成功");
              this.get_ClientInfo2();
              return;
            }).catch(res=>{
              this.$Message.error("发生502，请核查下终止");
              return;
            });
          } else if (this.risk_modall_title == '修改上终止') {
            params = {
              client_name: this.clientSelected,
              contract: this.contractSelected,
              value: this.updata_risk.end_up == '' ? "None" : this.updata_risk.end_up,
              end_up_type: this.updata_risk.end_up_type,
              end_up_price_type: this.updata_risk.end_up_price_type,
              type: 'end_up'
            };
            updateRisk(params).then(res => {
              this.risk_modall = false;
              if(res.status === 502){
                this.$Message.error("发生502，请核查上终止");
                return;
              }
              this.$Message.success("修改成功");
              this.get_ClientInfo2();
              return;
            }).catch(res=>{
              this.$Message.error("发生502，请核查上终止");
              return;
            });
          } else if (this.risk_modall_title == '修改止损时间') {
            params = {
              client_name: this.clientSelected,
              contract: this.contractSelected,
              value: this.updata_risk.end_time == '' ? "None" : new Date(this.updata_risk.end_time).getTime(),
              end_time_type: this.updata_risk.end_time_type,
              type: 'end_time'
            };
            updateRisk(params).then(res => {
              this.risk_modall = false;
              if(res.status === 502){
                this.$Message.error("发生502，请核查止损时间");
                return;
              }
              this.$Message.success("修改成功");
              this.get_ClientInfo2();
              return;
            }).catch(res=>{
              this.$Message.error("发生502，请核查止损时间");
              return;
            });
          }
        },
        risk_cancel() {
          this.end_time = this.client_info.risk.end_time !== 'None' ? TimeToDate(this.client_info.risk.end_time, 'year') : 'None'
        },
        //同步委托
        synchronous() {
          let params = {
            client: this.clientSelected, //用户ID（用户名）
            contract: this.contractSelected,//合约名称
          };
          synchronous(params).then(res => {
            this.synchronous_modall = false;
            if(res.status === 502){
              this.$Message.error("发生502，请核查同步委托");
              return;
            }
            if (res.data.code === 1000) {
              this.$Message.success('success');
              this.set_run_select_Ids([]);
              this.set_data_group_id_run([]);
              this.get_ListStrategy2();
            } else {
              this.$Message.error('error');
            }
          }).catch(res=>{
            this.$Message.error("发生502，请核查同步委托");
            return;
          })
        },
        //获取策略
        get_ListStrategy2() {
          let client = this.clientSelected; //用户ID（用户名）
          let contract = this.contractSelected;//合约名称
          this.getListStrategypro({client, contract}).then(res => {
            console.log(res);
          }).catch(err => {
            console.log(err)
          })
        },
        //获取某用户，某合约的点位平移策略
        getPointLocation() {

          let params = {
            client: this.clientSelected, //用户ID（用户名）
            contract: this.contractSelected,//合约名称
          };
          getListPointTranslation(params).then(res => {
            this.point_location_group = this.setSprintGroup(this.all_group);
            if (res.data.code === 1000) {
              if (res.data.data === undefined) {
                this.point_location_data = []
              } else {
                this.point_location_data = res.data.data

              }
            }

          })
        },
        //获取自动离场
        getListTimePrice() {
          let params = {
            client: this.clientSelected, //用户ID（用户名）
            contract: this.contractSelected,//合约名称
          };
          getListAutoleave(params).then(res => {
            if (res.data.code === 1000) {
              if (res.data.data === undefined) {
                this.time_triggered_data = []
              } else {
                this.time_triggered_data = res.data.data
                  .map(    //时间戳转时间
                    function (current, index, array) {
                      if (current.time !== 'None') {
                        current.time = TimeToDate(current.time, 'year')
                      }
                      return current
                    }
                  );
              }
            }
          })
        },
        //新增自动离场
        insertTimePrice() {
          let params = {
            client_name: this.clientSelected, //用户ID（用户名）
            contract_type: this.contractSelected,//合约名称
            time: this.time_triggered.time === '' ? '' : this.time_triggered.time.getTime(),
            before_after_time: this.time_triggered.before_after_time,
            price: this.time_triggered.price,
            price_type: this.time_triggered.price_type,
            hit_not_hit: this.time_triggered.hit_not_hit,
            group_type: this.time_triggered.group_type,
            group: this.time_triggered.group,
            position_type: this.time_triggered.position_type,
            command_type: this.time_triggered.command_type,
          };

          insertAutoleave(params).then(res => {
            if(res.status === 502){
              this.$Message.error("发生502，请核查自动离场");
              return;
            }
            if (res.data.code === 1000) {
              this.$Message.success('添加成功')
            } else {
              this.$Message.error(res.data.data.msg);
            }
            this.getListTimePrice()
          }).catch(res=>{
            this.$Message.error("发生502，请核查自动离场");
            return;
          });
          this.time_triggered = {
            strategy_id:'',
            time:'',
            price:'',
            price_type:'市价',
            hit_not_hit:'触及',
            group_type:'自定义分组',
            group:'',
            before_after_time: '之后',
            position_type:'未持仓',
            command_type:'停止',
          };
        },
        delete_time_triggered(){
          let param ={
            strategy_id:this.time_triggered_delete_id, //用户ID（用户名）
          };
          deleteAutoleave(param).then(res=>{
            this.time_triggered_delete_modall = false;
            if(res.status === 502){
              this.$Message.error("发生502，请核查自动离场");
              return;
            }
            this.$Message.success("删除成功");
            if(res.data.code === 1000){
              this.getListTimePrice()
            }
          }).catch(res=>{
            this.$Message.error("发生502，请核查自动离场");
            return;
          })
        },
        //新增自动平移
        insertPointLocation() {
          let params = {
            client: this.clientSelected, //用户ID（用户名）
            contract: this.contractSelected,//合约名称
            price_type: this.point_location.price_type,
            point: this.point_location.point,
            target_price_type: this.point_location.target_price_type,
            points_translation: this.point_location.points_translation,
            display_number: this.point_location.display_number,
            display_unit: this.point_location.type,
            waiting_time: this.point_location.type === '秒' ? this.point_location.display_number
              : this.point_location.type === '分' ? this.point_location.display_number * 60
                : this.point_location.type === '时' ? this.point_location.display_number * 60 * 60
                  : this.point_location.type === '天' ? this.point_location.display_number * 60 * 60 * 24
                    : this.point_location.display_number,
            command_type: this.point_location.command_type,
            command: this.point_location.command.join(","),
            inposition_type: this.point_location.inposition_type,
          };
          console.log(params)
          insertPointTranslation(params).then(res => {
            if(res.status === 502){
              this.$Message.error("发生502，请核查自动平移");
              return;
            }
            if (res.data.code === 1000) {
              this.$Message.success('添加成功');
              this.getPointLocation()
            } else if (res.data.code === 1010) {
              this.$Message.success('平移点数不合法，添加失败');
              this.getPointLocation()
            } else {
              this.$Message.error(res.data.data.msg);
            }
          }).catch(res=>{
            this.$Message.error("发生502，请核查自动平移");
            return;
          });
          this.point_location = {
            price_type:'市价',
            point:'',
            target_price_type:'固定平移',
            points_translation:'',
            display_number:'',
            waiting_time:'60',
            type:'秒',
            command_type:'自定义分组',
            command:'',
            inposition_type:'未持仓',
          };
        },
        delete_point_location(){
          let param ={
            strategy_id:this.point_location_delete_id, //用户ID（用户名）
          };
          deletePointTranslation(param).then(res=>{
            this.point_location_delete_modall = false;
            if(res.status === 502){
              this.$Message.error("发生502，请核查自动平移");
              return;
            }
            this.$Message.success("删除成功");
            if(res.data.code === 1000){
              this.getPointLocation()
            }
          }).catch(res=>{
            this.$Message.error("发生502，请核查自动平移");
            return;
          })
        },
        //保存编辑自动平移
        update_point_location_save() {
          let params = {
            client: this.clientSelected, //用户ID（用户名）
            contract: this.contractSelected,//合约名称
            strategy_id: this.update_point_location.strategy_id,
            point: this.update_point_location.point,
            price_type: this.update_point_location.price_type,
            target_price_type: this.update_point_location.target_price_type,
            command_type: this.update_point_location.command_type,
            command: this.update_point_location.command.join(","),
            points_translation: this.update_point_location.points_translation,
            display_number: this.update_point_location.display_number,
            display_unit: this.update_point_location.display_unit,

            waiting_time: this.update_point_location.display_unit === '秒' ? this.update_point_location.display_number
              : this.update_point_location.display_unit === '分' ? this.update_point_location.display_number * 60
                : this.update_point_location.display_unit === '时' ? this.update_point_location.display_number * 60 * 60
                  : this.update_point_location.display_unit === '天' ? this.update_point_location.display_number * 60 * 60 * 24
                    : this.update_point_location.display_number,
            inposition_type: this.update_point_location.inposition_type,
          };
          console.log(params)
          updatePointTranslation(params).then(res => {
            this.update_point_location_modall = false;
            if(res.status === 502){
              this.$Message.error("发生502，请核查自动平移");
              return;
            }
            if (res.data.code === 1000) {
              this.$Message.success('修改成功');
              this.getPointLocation()
            } else if (res.data.code === 1010) {
              this.$Message.success('平移点数不合法，添加失败');
              this.getPointLocation()
            } else {
              this.$Message.error(res.data.data.msg);
            }
          }).catch(res=>{
            this.$Message.error("发生502，请核查自动平移");
            return;
          });
          this.update_point_location = {
            price_type:'市价',
            point:'',
            target_price_type:'固定平移',
            points_translation:'',
            display_number:'',
            waiting_time:'60',
            type:'秒',
            command_type:'自定义分组',
            command:'',
            inposition_type:'未持仓',
          };
        },
        //退出编辑自动平移
        update_point_location_cancel() {
          this.update_point_location = {
            price_type:'市价',
            point:'',
            target_price_type:'固定平移',
            points_translation:'',
            display_number:'',
            waiting_time:'60',
            type:'秒',
            command_type:'自定义分组',
            command:'',
            inposition_type:'未持仓',
          };
        },
        //保存编辑自动离场
        update_time_triggered_save() {
          let params = {
            client_name: this.clientSelected, //用户ID（用户名）
            contract_type: this.contractSelected,//合约名称
            strategy_id: this.update_time_triggered.strategy_id,
            time: this.update_time_triggered.time === '' ? '' : this.update_time_triggered.time.getTime(),
            before_after_time: this.update_time_triggered.before_after_time,
            price: this.update_time_triggered.price,
            price_type: this.update_time_triggered.price_type,
            hit_not_hit: this.update_time_triggered.hit_not_hit,
            group_type: this.update_time_triggered.group_type,
            group: this.update_time_triggered.group,
            position_type: this.update_time_triggered.position_type,
            command_type: this.update_time_triggered.command_type,
          };
          updateAutoleave(params).then(res => {
            this.update_time_triggered_modall = false;
            if(res.status === 502){
              this.$Message.error("发生502，请核查自动离场");
              return;
            }
            if (res.data.code === 1000) {
              this.$Message.success('修改成功');
              this.getListTimePrice()
            } else {
              this.$Message.error(res.data.data.msg);
            }
          }).catch(res=>{
            this.$Message.error("发生502，请核查自动离场");
            return;
          });
          this.update_time_triggered = {
            strategy_id:'',
            time:'',
            price:'',
            price_type:'市价',
            hit_not_hit:'触及',
            group_type:'自定义分组',
            group:'',
            before_after_time: '之后',
            position_type:'未持仓',
            command_type:'停止',
          };
        },
        //退出编辑自动离场
        update_time_triggered_cancel() {
          this.update_time_triggered = {
            strategy_id:'',
            time:'',
            price:'',
            price_type:'市价',
            hit_not_hit:'触及',
            group_type:'自定义分组',
            group:'',
            before_after_time: '之后',
            position_type:'未持仓',
            command_type:'停止',
          };
        },
        //添加某用户，某合约的自动启动策略
        insertAutoStart() {
          let params = {
            client_name: this.clientSelected, //用户ID（用户名）
            contract_type: this.contractSelected,//合约名称
            time: this.auto_start.time === '' ?  '' : this.auto_start.time.getTime(),
            before_after_time: this.auto_start.before_after_time,
            price: this.auto_start.price,
            price_type: this.auto_start.price_type,
            hit_not_hit: this.auto_start.hit_not_hit,
            group_type: this.auto_start.group_type,
            group: this.auto_start.group,
          };
          insertAutorun(params).then(res => {
            if(res.status === 502){
              this.$Message.error("发生502，请核查自动启动");
              return;
            }
            if (res.data.code === 1000) {
              this.$Message.success("成功");
              this.getListAutorun()
            } else {
              this.$Message.error(res.data.data.msg);
            }
          }).catch(res=>{
            this.$Message.error("发生502，请核查自动启动");
            return;
          });
          this.auto_start = {
            strategy_id:'',
            time_price_or_price_time:'时间价格',
            time:'',
            price:'',
            price_type:'市价',
            before_after_time:'之后',
            hit_not_hit:'触及',
            group_type:'自定义分组',
            group:'',
          };
        },
        //获取某用户，某合约的自动启动策略
        getListAutorun() {
          let params = {
            client: this.clientSelected, //用户ID（用户名）
            contract: this.contractSelected,//合约名称
          };
          getListAutorun(params).then(res => {
            if (res.data.code === 1000) {
              if (res.data.data === undefined) {
                this.auto_start_data = []
              } else {
                this.auto_start_data = res.data.data
                  .map(    //时间戳转时间
                    function (current, index, array) {
                      if (current.time !== 'None') {
                        current.time = TimeToDate(current.time, 'year')
                      }
                      return current
                    }
                  );
              }
            }
          })
        },
        delete_Autorun(){
          let param ={
            strategy_id:this.auto_start_delete_id, //用户ID（用户名）
          };
          deleteAutorun(param).then(res=>{
            this.auto_start_delete_modall = false;
            if(res.status === 502){
              this.$Message.error("发生502，请核查自动启动");
              return;
            }
            this.$Message.success("删除成功");
            if(res.data.code === 1000){
              this.getListAutorun()
            }
          }).catch(res=>{
            this.$Message.error("发生502，请核查自动启动");
            return;
          })
        },
        //保存编辑某用户，某合约的自动启动策略
        update_auto_start_save() {
          let params = {
            strategy_id: this.update_auto_start.strategy_id,
            client_name: this.clientSelected, //用户ID（用户名）
            contract_type: this.contractSelected,//合约名称
            time: this.update_auto_start.time === '' ? '' : this.update_auto_start.time.getTime(),
            before_after_time: this.update_auto_start.before_after_time,
            price: this.update_auto_start.price,
            price_type: this.update_auto_start.price_type,
            hit_not_hit: this.update_auto_start.hit_not_hit,
            group_type: this.update_auto_start.group_type,
            group: this.update_auto_start.group,
          };
          updateAutorun(params).then(res => {
            this.update_auto_start_modall = false;
            if(res.status === 502){
              this.$Message.error("发生502，请核查自动启动");
              return;
            }
            if (res.data.code === 1000) {
              this.$Message.success('修改成功');
              this.getListAutorun()
            } else {
              this.$Message.error(res.data.data.msg);
            }
          }).catch(res=>{
            this.$Message.error("发生502，请核查自动启动");
            return;
          });
          this.update_auto_start = {
            strategy_id:'',
            time_price_or_price_time:'时间价格',
            time:'',
            price:'',
            price_type:'市价',
            before_after_time:'之后',
            hit_not_hit:'触及',
            group_type:'自定义分组',
            group:'',
          };
        },
        //退出编辑某用户，某合约的自动启动策略
        update_auto_start_cancel() {
          this.update_auto_start = {
            strategy_id:'',
            time_price_or_price_time:'时间价格',
            time:'',
            price:'',
            price_type:'市价',
            before_after_time:'之后',
            hit_not_hit:'触及',
            group_type:'自定义分组',
            group:'',
          };
        },
        //点击冲刺按钮
        clickSprint(){
          this.sprint_modall=true;
          this.getSprint();
        },
        //获取某用户，某合约的冲刺
        getSprint() {
          let params = {
            client: this.clientSelected, //用户ID（用户名）
            contract: this.contractSelected,//合约名称
          };
          getListSprint(params).then(res => {
            //0.设置sprint_group已启动所有策略
            this.sprint_group = this.setSprintGroup(this.all_group);
            if (res.data.code === 1000) {
              if (res.data.data === undefined) {
                this.sprint_data = []
              } else {
                this.sprint_data = res.data.data
                  .map(    //时间戳转时间
                     (current, index, array) =>{
                      if (current.time !== 'None' && current.time !== '') {
                        current.time = TimeToDate(current.time, 'year')
                      }
                      //可勾选冲刺分组
                      //1.分割,group_list
                      let temp_group_list = current.group_list.split(',');
                      temp_group_list.forEach((group)=>{
                        //2.判断已启动分组内是否有group_list分组，如果有剔除掉
                        let index = this.sprint_group.indexOf(group);
                        if( index > -1){
                          this.sprint_group.splice(index,1);
                        }
                      });
                      return current
                    }
                  );
                }
            }else{
              this.$Message.error(res.data.data.msg);
            }
          })
        },
        insertSprint(){
          if(this.sprint.sprint_trigger_type === '立即执行'){
            this.sprint.before_after_time =''
            this.sprint.time =''
            this.sprint.price =''
            this.sprint.price_type =''
          }
          let params = {
            client_name: this.clientSelected, //用户ID（用户名）
            contract_code: this.contractSelected,//合约名称
            sprint_trigger_type: this.sprint.sprint_trigger_type,//时间价格&价格时间
            before_after_time: this.sprint.before_after_time,
            time:  this.sprint.time === '' ? '' : this.sprint.time.getTime(),
            price: this.sprint.price,
            price_type: this.sprint.price_type,
            group_list: this.sprint.group_list.join(","),
            target_price_delt: this.sprint.target_price_delt,
            target_price_delt_type: this.sprint.target_price_delt_type,
            sprint_perform_interval: this.sprint.sprint_perform_interval,
            sprint_perform_interval_type: this.sprint.sprint_perform_interval_type,
            price_end: this.sprint.price_end,
            price_end_type: this.sprint.price_end_type,
            hit_not_hit: this.sprint.hit_not_hit,
            sprint_perform_time_interval_display_unmber: this.sprint.sprint_perform_time_interval_display_unmber,
            sprint_perform_time_interval_display_unit: this.sprint.sprint_perform_time_interval_display_unit,
            sprint_perform_time_interval: this.sprint.sprint_perform_time_interval_display_unit === '秒' ? this.sprint.sprint_perform_time_interval_display_unmber
              : this.sprint.sprint_perform_time_interval_display_unit === '分' ? this.sprint.sprint_perform_time_interval_display_unmber * 60
                : this.sprint.sprint_perform_time_interval_display_unit === '时' ? this.sprint.sprint_perform_time_interval_display_unmber * 60 * 60
                  : this.sprint.sprint_perform_time_interval_display_unit === '天' ? this.sprint.sprint_perform_time_interval_display_unmber * 60 * 60 * 24
                    : this.sprint.sprint_perform_time_interval_display_unmber,
          };
          insertSprint(params).then(res => {
            if(res.status === 502){
              this.$Message.error("发生502，请核查冲刺");
              return;
            }
            if (res.data.code === 1000) {
              this.$Message.success("成功");
              this.getSprint()
            } else {
              this.$Message.error(res.data.data.msg);
            }
          }).catch(res=>{
            this.$Message.error("发生502，请核查冲刺");
            return;
          });
          this.sprint = {
            sprint_strategy_id:'',
            client_name:'',
            contract_code:'',
            sprint_trigger_type:'价格时间',
            time:'',
            price_type:'市价',
            hit_not_hit:'触及',
            before_after_time:'之后',
            group_list:'',
            target_price_delt:'',
            target_price_delt_type:'固定数值',
            sprint_perform_interval:'',
            sprint_perform_interval_type:'固定数值',
            sprint_perform_time_interval:'',
            sprint_perform_time_interval_display_unmber:'',
            sprint_perform_time_interval_display_unit:'秒',
            price_end:'',
            price_end_type:'市价',
          };
        },
        delete_Sprint(){
          let param ={
            sprint_strategy_id:this.sprint_delete_id, //用户ID（用户名）
          };
          deleteSprint(param).then(res=>{
            this.sprint_delete_modall = false;
            if(res.status === 502){
              this.$Message.error("发生502，请核查冲刺");
              return;
            }
            this.$Message.success("删除成功");
            if(res.data.code === 1000){
              this.getSprint()
            }else{
              this.$Message.error(res.data.msg);
              this.getSprint()
            }
          }).catch(res=>{
            this.$Message.error("发生502，请核查冲刺");
            return;
          })
        },
        updateSprint_save(){
          if(this.update_sprint.sprint_trigger_type === '立即执行'){
            this.update_sprint.before_after_time =''
            this.update_sprint.time =''
            this.update_sprint.price =''
            this.update_sprint.price_type =''
          }
          let params = {
            sprint_strategy_id: this.update_sprint.sprint_strategy_id,
            client_name: this.clientSelected, //用户ID（用户名）
            contract_code: this.contractSelected,//合约名称
            sprint_trigger_type: this.update_sprint.sprint_trigger_type,//时间价格&价格时间
            before_after_time: this.update_sprint.before_after_time,
            time:  this.update_sprint.time === '' ? '' : this.update_sprint.time.getTime(),
            price: this.update_sprint.price,
            price_type: this.update_sprint.price_type,
            group_list: this.update_sprint.group_list,
            target_price_delt: this.update_sprint.target_price_delt,
            target_price_delt_type: this.update_sprint.target_price_delt_type,
            sprint_perform_interval: this.update_sprint.sprint_perform_interval,
            sprint_perform_interval_type: this.update_sprint.sprint_perform_interval_type,
            price_end: this.update_sprint.price_end,
            price_end_type: this.update_sprint.price_end_type,
            hit_not_hit: this.update_sprint.hit_not_hit,
            sprint_perform_time_interval_display_unmber: this.update_sprint.sprint_perform_time_interval_display_unmber,
            sprint_perform_time_interval_display_unit: this.update_sprint.sprint_perform_time_interval_display_unit,
            sprint_perform_time_interval: this.update_sprint.sprint_perform_time_interval_display_unit === '秒' ? this.update_sprint.sprint_perform_time_interval_display_unmber
              : this.update_sprint.sprint_perform_time_interval_display_unit === '分' ? this.update_sprint.sprint_perform_time_interval_display_unmber * 60
                : this.update_sprint.sprint_perform_time_interval_display_unit === '时' ? this.update_sprint.sprint_perform_time_interval_display_unmber * 60 * 60
                  : this.update_sprint.sprint_perform_time_interval_display_unit === '天' ? this.update_sprint.sprint_perform_time_interval_display_unmber * 60 * 60 * 24
                    : this.update_sprint.sprint_perform_time_interval_display_unmber,
            status:this.update_sprint.status
          };
          updateSprint(params).then(res => {
            this.update_sprint_modall = false;
            if(res.status === 502){
              this.$Message.error("发生502，请核查冲刺");
              return;
            }
            if (res.data.code === 1000) {
              this.$Message.success('修改成功');
              this.getSprint()
            } else {
              this.$Message.error(res.data.data.msg);
            }
          }).catch(res=>{
            this.$Message.error("发生502，请核查冲刺");
            return;
          });
          this.update_sprint = {
            sprint_strategy_id:'',
            client_name:'',
            contract_code:'',
            sprint_trigger_type:'价格时间',
            time:'',
            price_type:'市价',
            hit_not_hit:'触及',
            before_after_time:'之后',
            group_list:'',
            target_price_delt:'',
            target_price_delt_type:'固定数值',
            sprint_perform_interval:'',
            sprint_perform_interval_type:'固定数值',
            sprint_perform_time_interval:'',
            sprint_perform_time_interval_display_unmber:'',
            sprint_perform_time_interval_display_unit:'秒',
            price_end:'',
            price_end_type:'市价',
          };
        },
        updateSprint_cancel() {
          this.update_sprint = {
            client_name:'',
            contract_code:'',
            sprint_trigger_type:'价格时间',
            time:'',
            price_type:'市价',
            hit_not_hit:'触及',
            before_after_time:'之后',
            group_list:'',
            sprint_perform_type:'整体',
            target_price_delt:'',
            target_price_delt_type:'固定数值',
            sprint_perform_interval:'',
            sprint_perform_interval_type:'固定数值',
            price_end:'',
            price_end_type:'市价',
          };
        },
        contract_selected() {
          if (this.contractSelected !== undefined) {
            this.set_contract(this.contractSelected);
          }
        },
        //获取基础参数
        get_BasicParameter2() {
          let client = this.clientSelected; //用户ID（用户名）
          let contract = this.contractSelected;//合约名称
          this.getBaseParamter({client, contract}).then(res => {
            console.log(res);
          }).catch(err => {
            console.log("获取基础参数失败")
          })
        },
        //获取批量参数
        get_BatchParameter2() {
          let client = this.clientSelected; //用户ID（用户名）
          let contract = this.contractSelected;//合约名称
          this.getBatchParamter({client, contract}).then(res => {
            console.log(res);
          }).catch(err => {
            console.log(err)
          })
        },
        //设置颜色
        rowClassName1(row, index) {
          var patt1 = /空/;
          var patt2 = /多/;
          var patt3 = /全部/;
          if (patt1.test(row.group)) {
            return 'demo-table-sell-row';
          } else if (patt2.test(row.group)) {
            return 'demo-table-buy-row';
          } else if (patt3.test(row.group)) {
            console.log(name)
            return 'demo-table-all-row';
          }
        },
        rowClassName2(row, index) {
          var patt1 = /空/;
          var patt2 = /多/;
          var patt3 = /全部/;
          if (patt1.test(row.command)) {
            return 'demo-table-sell-row';
          } else if (patt2.test(row.command)) {
            return 'demo-table-buy-row';
          } else if (patt3.test(row.command)) {
            console.log(name)
            return 'demo-table-all-row';
          }
        },
        rowClassName3(row, index) {
          var patt1 = /空/;
          var patt2 = /多/;
          var patt3 = /全部/;
          if (patt1.test(row.group_list)) {
            return 'demo-table-sell-row';
          } else if (patt2.test(row.group_list)) {
            return 'demo-table-buy-row';
          } else if (patt3.test(row.group_list)) {
            return 'demo-table-all-row';
          }
        },
        //设置必须有多或空的冲刺分组
        setSprintGroup(gourp_list){
          var patt1 = /空/;
          var patt2 = /多/;
          let new_group = [];
          gourp_list.forEach((group) =>{
            if(patt1.test(group)  || patt2.test(group)){
              new_group.push(group)
            }
          });
          return new_group;
        },
        max_profit_and_loss_change(status){
          clearTimeout(this.flag_setTimeout)
          if(this.flag){
            this.$Message.error('点击频率太快，3秒后重试');
          }else {
            let params = {
              client_name: this.clientSelected, //用户ID（用户名）
              contract_code: this.contractSelected,//合约名称
              profit_loss_cal_status_unrun: status,
            };
            updateProfitLossCal(params).then(res => {
              if(res.status === 502){
                this.$Message.error("发生502，请核查同步委托");
                return;
              }
              if (res.data.code === 1000) {
                if(status){
                  this.$Message.info('包含未启动' );
                }else {
                  this.$Message.info('不包含未启动' );
                }
              } else {
                this.$Message.error(res.data.msg);
              }
            }).catch(res=>{
              this.$Message.error("异常错误，请核查盈亏计算切换是否包含未启动");
              return;
            })
          }
          this.flag = true;//点击之后设置按钮不可使用
          this.flag_setTimeout = setTimeout(()=>{this.flag = false;}, 3000);
        },
        target_price_type_change(value){
          if(value === '触及价附近'){
            this.point_location.inposition_type = '未持仓'
          }
        },
        target_price_type_change2(value){
          if(value === '触及价附近'){
            this.update_point_location.inposition_type = '未持仓'
          }
        },
        target_price_type_change3(value){
          this.point_location.command = ''
        },
        target_price_type_change4(){
          this.update_point_location.command = ''
        },
        get_clientSelected(){
          this.$Message.error(this.contractSelected);
        }
      },
      computed:{
        computed_client_list(){
          return this.get_client_list()
        },
        computed_contract_list(){
          return this.get_contract_list()
        },
        computed_client(){   //vux要监听对象
          return this.get_client()
        },
        computed_contract(){
          return this.get_contract()
        },
        computed_client_info(){
          return this.get_client_info()
        },
        computed_price(){
          return this.get_price()
        },
        client_and_contract(){   //如果client和contract都发生改变执行
          const  { clientSelected,contractSelected} = this;
          return {
            clientSelected,
            contractSelected
          }
        },
        computed_run_group(){
          return this.get_run_group();
        },
        computed_unrun_group(){
          return this.get_unrun_group();
        },
        computed_all_group(){
          return this.get_all_group();
        },
      },
      watch:{
        computed_client_list(){
          this.client_list = this.get_client_list();
        },
        computed_contract_list(){
          this.contract_list = this.get_contract_list()
        },
        computed_client(){
          this.clientSelected = this.get_client();
        },
        computed_contract(){
          this.contractSelected = this.get_contract()
        },
        computed_client_info(){
          if(this.get_client_info() !==''){
            this.client_info = this.get_client_info();
            if(this.client_info.risk.end_time !== 'None' || this.client_info.risk.end_time !== ''){
              this.end_time = this.client_info.risk.end_time !== 'None' ? TimeToDate(this.client_info.risk.end_time, 'year') :'None'
            }
            if(this.client_info.account_status === "爆仓"){
                this.stopClientInfoPro()
              this.$Modal.error({
                title: "爆仓了",
              });
            }
          }else {
            this.client_info={
              basic:{},
              risk:{},
            };
          }
        },
        computed_price(){
          this.price = this.get_price();
          if(this.price.price_of_stop_profit_and_stop_loss ==="price_index"){
            this.compare_price = this.price.price_index
          }else {
            this.compare_price = this.price.price_now
          }
        },
        client_and_contract(){ //获取到用户id和合约后执行的方法
          if(this.clientSelected !== '' && this.contractSelected !=='' && this.contractSelected !==undefined){
            this.get_ClientInfo2();
          }
        },

        clientSelected(){
          this.contractSelected = '';
          this.set_run_select_Ids([]);
          this.set_unrun_select_Ids([]);
          this.set_run_group([]);
          this.set_unrun_group([]);
          this.set_all_group([]);
          this.set_data_group_id_run([]);
          this.set_data_group_id_unrun([]);
          this.set_base_paramter([]);
          this.set_batch_paramter([]);
          this.set_list_strategy([]);
          this.set_list_strategy_unrun([]);
          this.set_list_strategy_run([]);
          if(this.clientSelected !== undefined){
            this.set_client(this.clientSelected);
          };
          //切换合约名
          if(this.get_contract_list() !=="" &&this.get_contract_list() !==undefined && this.get_contract_list().length !==0){
            this.contract_list = this.get_contract_list();
            if(this.get_contract() !== ''){
              this.contractSelected = this.get_contract()
            }
          }else {
            this.contractSelected = '';
            this.set_contract('');
            this.get_contract2();
          }
          this.sprint_data = []
          this.point_location_data = []
          this.time_triggered_data = []
          this.auto_start_data = []
        },
        computed_run_group(){
          this.run_group = this.get_run_group();
        },
        computed_unrun_group(){
          this.unrun_group = this.get_unrun_group();
        },
        computed_all_group(){
          this.all_group = this.get_all_group();
        },
      }
    }
</script>

<style scoped lang="less">
button {
  border: 0;
  border-radius: 4px;
  font-size: 14px;
  letter-spacing: 0;
  cursor: pointer;

}
.trade_header{
  position: relative;
  height: 140px;
  margin-bottom: 10px;
  display: flex;
  .h_left{
    width: 17%;
    .hl_m{
      margin-left: 14*4/3px;
      .hl_1{
        text-align: center;
        margin-top: 8*4/3px;
        font-size: 18px;
        letter-spacing: 0;
      }
      .hl_2{
        margin-top: 7px;
        /deep/ .ivu-select-placeholder{
          width: 120*4/3px;
          height: 32px;
          line-height: 32px;
        }
        button {
          margin-left: 20px;
          width: 79*4/3px;
          height: 32px;
          background: #4EA7F3;
          font-size: 14px;
          color: #FFFFFF;
          text-align: center;
        }
        button:focus{outline:0;}
        button:hover{
          opacity: 0.95;
        }
      }
      .hl_3{
        margin-top: 10px;
        display: flex;
        .price{
          width: 150px;
          font-size: 14px;
          letter-spacing: 0;
          em{
            font-size: 18px;
            letter-spacing: 0;
          }
        }
        .hl_wt{
          margin-left: 14px;
          button{
            background-color:  transparent;
            width: 79*4/3px;
            height: 32px;
            font-size: 14px;
            color: #80C4FF;
            letter-spacing: 0;
            text-align: center;
            border: 1px solid #80C4FF;
            border-radius: 2px;
            cursor: pointer;
          }
          button:focus{outline:0;}
        }
      }
    }
  }
  .d1{
    position:absolute;
    left:16.5%;
    top:10px;
    z-index:1;
    height: 86%;
    float: right;
  }
  .h_main{
    width: 17%;
    .hm_m{
      margin-left: 5px;
      .hm_1{
        text-align: center;
        margin-top: 8px;
        font-size: 18px;
        letter-spacing: 0;
      }
      .hm_2{
        display: flex;
        .hm_2_list{
          width: 78px;
          font-size: 14px;
          letter-spacing: 0;
          text-align: center;
          .hm_2_p2{
            margin-top: 18px;
          }
        }
      }
    }
  }

  .d2{
    position:absolute;
    left:33%;
    top:10px;
    z-index:1;
    height: 86%;
    float: right;
  }
  .h_centre{
    width: 21%;
    .hm_m{
      margin-left: 5px;
      .hm_1{
        text-align: center;
        margin-top: 8px;
        .hm_1_s{
          display: inline-block;
          vertical-align:bottom;
          font-size: 18px;
          height: 22px;
          letter-spacing: 0;
        }
      }
      .hm_2{
        .col-th{
          display: flex;
          .col-td{
            width: 74px;
            font-size: 14px;
            letter-spacing: 0;
            text-align: center;
          }
        }
        .col-tr{
          margin-top: 5px;
          display: flex;
          .col-td{
            width: 74px;
            font-size: 14px;
            letter-spacing: 0;
            text-align: center;
          }
        }
      }
    }
  }
  .d3{
    position:absolute;
    left:53.4%;
    top:10px;
    z-index:1;
    height: 86%;
    float: right;
  }
  .h_right{
    width: 36%;
    .hr_m{
      margin-left: 2px;
      .hr_1{
        text-align: center;
        margin-top: 8px;
        font-size: 18px;
        letter-spacing: 0;
      }
      .hr_2{
        display: flex;
        .hr_2_list{
          width: 85px;
          font-size: 14px;
          text-align: center;
          .hr_2_p2{
            margin-top: 18px;
          }
          i{
            display: inline-block;
            width: 12px;
            height: 12px;
            background: url(../../../../static/img/edit-浅.png);
            cursor: pointer;
          }
        }
      }
    }
  }
  .h_extra{
    width: 11.5%;
    margin-top: 20px;
    padding-right: 10px;
    display: flex;
    button{
      width: 32px;
      height: 90px;
      margin-right: 10px;
      padding: 5px;
      color: #FFFFFF;
      text-align: center;
      line-height: 18px;
    }
    .he_button1{
      background-image: linear-gradient(-45deg, #3F53F0 0%, #58E3FE 100%);

    }
    .he_button2{
      background-image: linear-gradient(-218deg, #5D3FB1 0%, #4AABFF 100%);
    }
    .he_button3{
      background-image: linear-gradient(-45deg, #3F53F0 0%, #58E3FE 100%);
    }
    .he_button4{
      background-image: linear-gradient(-225deg, #3F53F0 0%, #58E3FE 100%);

    }
  }
  .ivu-switch-small:after {
    width: 8px;
    height: 8px;
  }
  .ivu-switch-small {
    width: 24px;
    height: 12px;
    line-height: 10px;
  }
}
</style>
